/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/controls/UniButton.h,v 1.5 2003/11/21 12:39:24 itsme Exp $
 *
 *
 */


#if !defined(AFX_UNIBUTTON_H__EBEB2EA0_A067_11D2_9E44_0020182F735A__INCLUDED_)
#define AFX_UNIBUTTON_H__EBEB2EA0_A067_11D2_9E44_0020182F735A__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
/////////////////////////////////////////////////////////////////////////////
// CUniButton window
//
// AUTHOR: Pavel A .Simakov
// DATE: 981226
// E-MAIL: psimakov@outplay.com
// ORGANIZATION: Outplay Consulting
// HTTP: www.outplay.com
// TERM OF USE: unlimited, must cite AUTHOR
// COPYRIHT: 1998 Outplay Consulting
//
/////////////////////////////////////////////////////////////////////////////

// see http://www.codeguru.com/buttonctrl/UniButton.shtml

class CUniButton : public CButton
{
public:
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CUniButton)
    public:
    virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
    protected:
    virtual void PreSubclassWindow();
    virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
    //}}AFX_VIRTUAL

protected:
    //{{AFX_MSG(CUniButton)
    afx_msg BOOL OnClick();
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
    //}}AFX_MSG

    afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
    afx_msg void OnTimer( UINT nIDEvent );

    DECLARE_MESSAGE_MAP()
private:
    UINT m_nBorder;                                                     // width of the border in pixels for 3D highlight
    LONG m_lfEscapement;                                                // orientation of the caption (in tenth of the degree as in LOGFONT)
    COLORREF m_nColor, m_sColor, m_dColor;                              // background colors for button states: normal, selected, disabled
    CBitmap * m_pNormal;                                                // bitmaps to hold button images
    CBitmap * m_pSelected;
    CBitmap * m_pChecked;
    CBitmap * m_pDisabled;

    bool m_bChecked;

    UINT m_iCnt, m_iIndex;
    BOOL m_bPressed, m_bHit;
    char m_cChar;
    UINT m_iRepCnt;
    DWORD m_dwStyle;
    HCURSOR m_hCursor;
    CPoint m_CenterPoint;                                               // button caption will be centered around this point
    BOOL m_bMouseDown;                                                  // indicated that mouse is pressed down
    BOOL m_bCapture;                                                    // indicates that mouse is captured in the buton
    HRGN m_hRgn;                                                        // region in screen coordinates
    BOOL m_bNeedBitmaps;                                                // flag idicates that state bitmaps must be rebuild
    void DrawButton(CDC * pDC, CRect * pRect, UINT state);              // draws button to the screen
    //void PrepareStateBitmaps(CDC * pDC, CRect * pRect);                   // prepares bitmaps for button states
    BOOL HitTest(CPoint point);                                         // determines if point is inside the button region
protected:
/*
    void PrepareNormalState(CDC * pDC, CDC * pMemDC, CRect * pRect);    // prepare normal state button bitmap
    void PrepareSelectedState(CDC * pDC, CDC * pMemDC, CRect * pRect);  // prepare selectedstate button bitmap
    void PrepareDisabledState(CDC * pDC, CDC * pMemDC, CRect * pRect);  // prepare disabled state button bitmap
*/
    void PaintRgn(CDC * pDC, CDC * pMemDC, CBitmap * pBitmap, COLORREF color, CRect * pRect, BOOL bEnabled, BOOL bSunken);  // paint button
    BOOL SetupRegion(CDC *pDC, unsigned short nBMask);
    void SetupSquareRegion(CDC *pDC, unsigned short nBMask, UINT cnt= 1 );
    void LoadIndexedBitmap( CBitmap *pBitmap, CDC *pDC, UINT nID, UINT index, UINT cnt );
    void MakeChar();

public:
    CUniButton();               // constructor
    virtual ~CUniButton();  // destructor

/*
    BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle, const CPoint point, const HRGN hRgn, CWnd* pParentWnd, UINT nID);
                            // constructor with default colors and border
    BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle, const CPoint point, const HRGN hRgn, CWnd* pParentWnd, UINT nID, COLORREF color);
                            // constructor with hover & selected color specified

    BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle, const CPoint point, const HRGN hRgn, CWnd* pParentWnd, UINT nID, UINT nBorder, COLORREF nColor, COLORREF sColor, COLORREF dColor);
                            // complex parameters constructor
                                // lpszCaption - window caption
                                // dwStyle - window styles
                                // point - position of the button on the parent window (in parent coordinates)
                                // hRgn - handle to region which represents the button (in button client coordinates)
                                // pParentWnd - handle to parent window
                                // nID - control Id
                                // nBorder - specifies width of the border in pixels for 3D highlight (allowed values are 1, 2)
                                // nColor - normal color
                                // sColor - selected color
                                // dColor - disabled color
    BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle, const CPoint point, const HRGN hRgn, CWnd* pParentWnd, UINT nID, UINT nBorder, LONG lfEscapement, COLORREF nColor, COLORREF sColor, COLORREF dColor);
                                // variation of above
*/
    // constructor with bitmaps specified
    //BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle, CDC *pDC, const CPoint point, CWnd* pParentWnd, UINT nID, UINT nBMask, UINT nBNormal, UINT nBSelected, UINT nBDisabled= 0, UINT index= 0, UINT cnt= 1 );

    BOOL CreatePushButton(CDC *pDC, const RECT& pos, CWnd* pParentWnd, UINT nID,
            UINT nBMask, UINT nBNormal, UINT nBSelected, UINT nBDisabled);
    BOOL CreateCheckButton(CDC *pDC, const RECT& pos, CWnd* pParentWnd, UINT nID,
            UINT nBMask, UINT nBNormal, UINT nBSelected, UINT nBChecked, UINT nBDisabled);

    void SetChar( char c );
    void SetCheck( bool bCheck );
    bool GetCheck( );
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_UNIBUTTON_H__EBEB2EA0_A067_11D2_9E44_0020182F735A__INCLUDED_)
